package com.ezops.businessprocess.integration.usermanagement;

import org.activiti.engine.identity.User;
import org.activiti.engine.identity.UserQuery;
import org.activiti.engine.impl.persistence.entity.UserEntity;
import org.activiti.engine.impl.persistence.entity.UserEntityManager;
import org.activiti.engine.impl.persistence.entity.UserIdentityManager;

import com.ezops.businessprocess.integration.identity.EzopsUserQuery;
import com.ezops.model.EzopsUserProfile;
import com.ezops.poc.dao.UserDAO;

/**
 * Custom implementation of {@link UserIdentityManager} to override the
 * underlying data layer.
 * <p>
 * This class uses EZOPS internal table and data access layers for application
 * user and group. Activiti will use this class as the main user/group data
 * provider
 * 
 * @author vgaurav
 * 
 */
public class EzopsUserEntityManager extends UserEntityManager {

	private UserDAO userDao;

	public EzopsUserEntityManager() {
		super();
	}

	@Override
	public UserEntity findUserById(String userId) {
		// return super.findUserById(userId);
		EzopsUserProfile aUser = userDao.findUserByLoginName(userId);
		UserEntity userEntity = new UserEntity(aUser.getLoginName());
		userEntity.setEmail(aUser.getEmailAddress());
		userEntity.setFirstName(aUser.getFirstName());
		userEntity.setLastName(aUser.getLastName());
		return userEntity;
	}
	@Override
	public UserQuery createNewUserQuery() {
		EzopsUserQuery aUserQuery = new EzopsUserQuery();
		aUserQuery.setUserDao(userDao);
		return aUserQuery;
	}
	
	@Override
	public Boolean checkPassword(String userId, String password) {
		return Boolean.TRUE;
	}

	@Override
	public void insertUser(User user) {
		throw new IllegalArgumentException("Not impl");
	}

	

	@Override
	public void deleteUser(String userId) {
		throw new IllegalArgumentException("Not impl");
	}

	@Override
	public void flush() {
		super.flush();
	}

	@Override
	public void close() {
		super.close();
	}

	public void setUserDao(UserDAO userDao) {
		this.userDao = userDao;
	}

}
